<?php
    namespace Npfe\Controller;
    use Think\Controller;
    class MainController extends Controller{
        function nocgdadd(){
            $this->display('npfe_nocadd');
        }
        function nocgdedit($snid,$time){
            $table_change=array(
                'snid' => $snid,
                'time' => $time,
            );
            $noc = new \Npfe\Model\NocModel();
            $data = $noc->where("snid = '$snid' && time = '$time'")->find();

            if ($data != false) {
                $table_change['cname'] = $data['cname'];
                $table_change['cnumber'] = $data['cnumber'];
                $table_change['fanying'] = $data['fanying'];
                $table_change['huifu'] = $data['huidan'];
                $table_change['gdlb'] = $data['gdlb'];
            }else {
                $table_change['cname'] = '获取失败';
                $table_change['cnumber'] = '获取失败';
                $table_change['fanying'] = '获取失败';
            }

            $this->assign($table_change);
            $this->display('npfe_nocedit');
        }
        public function hotline(){
            $this->assign('now_em',session('nickname'));
            $this->display();
        }
        public function searchxiaojie($value=NULL){
            # 查询小结...
            $dmt = self::getdmt();
            $items = array();
            $ckb = new \Npfe\Model\CkbModel();
            $res;
            if (isset($value)) {
                $res = $ckb->where("czj='$value'")->select();
            }else{
                $res = $ckb->where("date >= '$dmt[dmtb]' and date <= '$dmt[dmte]'")->select();
            }

            foreach($res as $row){
                array_push($items, $row);
            }
            $value =array(
                "total" => count($items),
                'rows' => $items
            );
            $nonetr = json_encode($value);
            echo $nonetr;
        }
        public function addcomrec(){
            $ckb = new \Npfe\Model\CkbModel();
            $data = array(
                'date'=>I('post.date'),
                'cname'=>I('post.cname'),
                'czj'=>I('post.czj'),
                'cnumber'=>I('post.cnumber'),
                'stt'=>I('post.date'),
                'ste'=>'',
                'leaght'=>'0',
                'xjlb'=>I('post.xjlb'),
                'isend'=>I('post.isend'),
                'yuanyin'=>I('pose.yuanyin'),
                'dafu'=>I('post.dafu'),
                'ctlman'=>I('post.ctlman')
            );
            $ckb->add($data);
            echo 'success';
        }
        public function getdmt(){
            $y=date("Y",time());
            $m=date("m",time());
            $d=date("d",time());
            $t0=date('t');           // 本月一共有几天
            $t1=mktime(0,0,0,$m,1,$y);        // 创建本月开始时间
            $t2=mktime(23,59,59,$m,$t0,$y);       // 创建本月结束时间
            $rdate['today'] = date("Y-m-d",time());
            $rdate['dmtb'] = date("Y-m-d H:i:s",$t1);
            $rdate['dmte'] = date("Y-m-d H:i:s",$t2);
            $rdate['sjc'] = $t2-$t1;
            return $rdate;
        }

        public function formattime($stt,$ett){
            $formated['stt'] = date('Y-m-d H:i:s',strtotime($stt));
            $formated['ett'] = date('Y-m-d H:i:s',strtotime($ett));
            return $formated;
        }
    }

?>